@extends('default.layouts.adminPublic')
@section('title', '资讯管理列表')

@section('content')
<!--导航开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin')}}">首页</a> &raquo; 资讯管理
</div>
<!--导航结束-->

<!--列表开始-->

    <div class="result_wrap">
        <div class="search">
            <form name="Formso" id="Formso" action="{{url('/admin/new_list/')}}" method="post">
                {{csrf_field()}}
                <span>关键字：</span>
                        <span><input name="keyword" class="keyword" id="keyword" placeholder="请输入资讯名称"
                                     type="text"></span>
                <select name="category" id="category" style="width:140px;">
                    <option value="">请选择资讯分类</option>
                    @if(count($newsCategory) > 0)
                        @foreach($newsCategory as $v)
                            <option value="{{$v->id}}">{{$v->defectsname}}</option>
                        @endforeach
                    @endif
                </select>
                <span><input name="submit" class="skeyword" value="搜索" type="submit"></span>
            </form>
        </div>
        <div class="message" style="margin-top: 15px;">
            <p><span style="margin-right: 20px; font-size: 15px;"><a href="{{url('admin/news/create')}}"><i
                                class="fa fa-plus"></i>添加资讯</a></span>
                        <span>目前共查找到<strong
                                    style="color:#ff4400">{{$news->total()}}</strong>个资讯！且每页显示资讯记录{{$news->perPage()}}
                            个。</span>
            </p>
        </div>
    </div>

    <div class="result_wrap">
        <div class="result_content">
            <ul class="list_tab make">
                <li class="title border_buttom">
                    <span class="first">序号</span>
                    <span class="second ">标题</span>
                    <span class="third">来源</span>
                    <span class="four">类别</span>
                    <span class="five">更新时间</span>
                    <span class="six">操作</span>
                </li>
                @foreach($news as $k => $v)
                    <li class="@if($k % 2 == 0) saith_bg @else double_bg @endif border_buttom">
                        <span class="first">{{ $k+1 }}</span>
                        <span class="second">{{ msubstr($v->title,0,15) }}</span>
                        <span class="third">{{ $v->source }}</span>
                        <span class="four">{{ $v->newsWithCategory->defectsname or ''}}</span>
                        <span class="five">{{ $v->updated_at }}</span>
                        <span class="six">
                            <a href="{{ url('admin/news/'.$v->id.'/edit') }}">修改</a>
                            <a  onclick="delNews(this,'{{ $v->id }}','{{ $v->title }}')">删除</a>
                        </span>
                    </li>
                @endforeach
            </ul>
        </div>
    </div>
<div class="page_list">
    <div>{!! $news->appends($input)->links() !!}</div>
</div>
<!--列表结束-->
<script type="text/javascript">
    //删除资讯
    function delNews(othis,id,title) {
        layer.confirm('您确定要删除这条资讯信息吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.post("{{url('admin/news')}}/" + id, {
                '_method': 'delete',
                '_token': "{{csrf_token()}}",
                'title': title
            }, function (data) {
                if (data.status == 0) {
                    location.href="{{ url('/admin/news') }}";
                } else {
                    location.href="{{ url('/admin/news') }}";
                }
            });
        });
    }
</script>
@endsection